import { createSlice } from '@reduxjs/toolkit'
import { allCategory, category1, category2, category3 } from '@api/user/category'


const categorySlice = createSlice({
    name: 'category',
    initialState: {
        category1List: [] as category1[],
        category2List: [] as category2[],
        category3List: [] as category3[],
        allCategoryList: [] as allCategory[]
    },
    reducers: {
        changeCategory1List(state, {payload}) {
            state.category1List.push(...payload)
        },
        changeCategory2List(state, {payload}) {
            state.category2List = []
            state.category3List = []
            state.category2List.push(...payload)
        },

        changeCategory3List(state, {payload}) {
            state.category3List = []
            state.category3List.push(...payload)
        },
        changeAllCategoryList(state, {payload}) {
            state.allCategoryList = []
            state.allCategoryList.push(...payload)
        }
    }
})

export let {
    changeCategory1List,
    changeCategory2List,
    changeCategory3List,
    changeAllCategoryList
} = categorySlice.actions


export default categorySlice.reducer